#pragma once
#include "type.h"
#include "cocos2d.h"

class savegame
{
private:
	const int _typecount = 10;
	const short MAX_ITEM_AMOUNT = 400;

	struct TTeamlist
	{
		short  number, amount;
	};
	struct TBasic_data
	{
	public:
		short inship, where, My, Mx, Sy, Sx, Mface, shipx, shipy, time, timeevent, randomevent, Sface, Shipface, teamcount, teamlist[6];
		TTeamlist RItemlist[400];

	};

	struct TRole
	{
	public:
		short ListNum, HeadNum, IncLife, fuyuan;
		char Name[10];
		short zhanwei1;
		char Nick[10];
		short zhanwei2, Sexual, Level;

		unsigned short Exp;//18
		short CurrentHP, MaxHP, Hurt, Poision, PhyPower; //23
		short FightNum;
		short Equip[5]; // 30
		short Gongti, TeamState, Angry, israndomed, Moveable, In_HeadNum, ZhanLueAI, Impression,
			dtime, difficulty, zhongcheng, rehurt, MPType, CurrentMP, MaxMP, Attack, Speed, Defence,
			Medcine, UsePoi, MedPoi, DefPoi, Fist, Sword, Knife, Unusual, HidWeapon, Knowledge, Ethics,
			AttPoi, AttTwice, Repute, Aptitude, PracticeBook;
		unsigned short ExpForBook; //64
		short xiangxing, jiaoqing, Rtype, swq, pdq, xxq, jqq, MenPai, shifu, scsx, bssx; //75
		short Choushi[2];
		short weizhi, nweizhi, nfangxiang, unuse0, lwq, msq, ldq, qtq, lsweizhi, lsnweizhi, lsfangxiang,
			Sx, Sy, songshu, gongxian, unuse5, unuse6, unuse7, unuse8, unuse9, btnum; //98
		short LMagic[30], MagLevel[30]; //158
		short TakingItem[4], TakingItemAmount[4], jhMagic[10], LZhaoshi[30], MRevent, AllEvent[9], leaveevent;

	};

	struct TItem
	{
		short ListNum;
		char Name[20];
		short Zhanwei1, ExpOfMagic, SetNum, BattleEffect, WineEffect, NeedSex, Rehurt, unuse[4]; //21
		char Introduction[30]; //36
		short Zhanwei2, Magic, AmiNum, User, EquipType, ShowIntro, ItemType, inventory, price, EventNum; //46
		short AddCurrentHP, AddMaxHP, AddPoi, AddPhyPower, ChangeMPType, AddCurrentMP, AddMaxMP, AddAttack, AddSpeed,
			AddDefence, AddMedcine, AddUsePoi, AddMedPoi, AddDefPoi; //60
		short AddFist, AddSword, AddKnife, AddUnusual, AddHidWeapon, AddKnowledge, AddEthics, AddAttTwice, AddAttPoi; //69
		short OnlyPracRole, NeedMPType, NeedMP, NeedAttack, NeedSpeed, NeedUsePoi, NeedMedcine, NeedMedPoi; //77
		short NeedFist, NeedSword, NeedKnife, NeedUnusual, NeedHidWeapon, NeedAptitude; //83
		short NeedExp, Count, Rate; //86
		short NeedItem[5], NeedMatAmount[5];
	};
	struct TScene
	{
		short ListNum;
		char Name[10];
		short Zhanwei1, ExitMusic, EntranceMusic, Pallet, EnCondition; //10
		short MainEntranceY1, MainEntranceX1, MainEntranceY2, MainEntranceX2, EntranceY, EntranceX, ExitY[3], ExitX[3]; //22
		short Mapmode, unuse, menpai, inbattle, zlwc, lwc, zcjg, cjg; //30
		short lwcx[5], lwcy[5], cjgx[5], cjgy[5]; //50
		short bgskg, bgsx, bgsy, ldlkg, ldlx, ldly, bqckg, bqcx, bqcy, qizhix, qizhiy, ldjd, dzjd, fyjc, fyss; //65
		short addziyuan[10], lianjie[10];
	};

	struct TMagic
	{
		short ListNum;
		char Name[10];
		short Zhanwei1, useness, miji, NeedHP, MinStep, bigami, EventNum, SoundNum, MagicType, AmiNum, HurtType, AttAreaType,
			NeedMP, Poision, MinHurt, MaxHurt, HurtModulus, AttackModulus, MPModulus, SpeedModulus, WeaponModulus,
			Ismichuan, AddMpScale, AddHpScale, MoveDistance[10], AttDistance[10];
		short AddHP[3], AddMP[3], AddAtt[3], AddDef[3], AddSpd[3];
		short MinPeg, MaxPeg, MinInjury, MaxInjury, AddMedcine, AddUsePoi, AddMedPoi, AddDefPoi, AddFist, AddSword, AddKnife,
			AddUnusual, AddHidWeapon, BattleState, NeedExp[3];
		short MaxLevel;
		char Introduction[60];
		short Zhanwei2, zhaoshi[5], teshu[10], teshumod[10];
	};

	struct TShopitem
	{
		short inum, amount;
	};
	struct TShop
	{
		TShopitem shopItem[18];
	};
	struct TTexiao
	{
		short x, y;
	};
	struct TDate
	{
		short Jiazi, year, moon, day, hour;
	};
	struct TZhaoshi
	{
		short daihao, congshu, shunwei;
		char Name[20];
		short zhanwei1, ygongji, gongji, yfangyu, fangyu;
		short shuoming[46]; //40
		short Zhanwei2;
		TTexiao texiao[24];
	};
	struct TMenpai
	{
		short num;
		char Name[20];
		short zhanwei1, jvdian, zongduo, zmr, dizi, shengwang, shane; //17
		short ziyuan[10], aziyuan[10], neigong[20]; //57
		short guanxi[40]; //97
		short zhiwu[10]; //107
		short kzq, dzq, czsd, qizhi, mdizigrp, mdizipic, fdizigrp, fdizipic, sexy, identity, endevent, tongmeng, unuse1, unuse2,
			unuse3, unuse4;
	};

public:
	savegame();
	~savegame();
	unsigned char key = 182;
	unsigned char password;	
	unsigned char *Data;
	int *Offset;
	int grplen;
	int idxlen = _typecount * 4;
	unsigned char GRPMD5_cal[32], GRPMD5_load[32];
	TBasic_data Rbasic_data;
	TRole *Rrole;
	int R_count;
	TItem *Ritem;
	int I_count;
	TScene *Rscene;
	int S_count;
	TMagic *Rmagic;
	int M_count;
	TShop *Rshop;
	int SP_count;
	TDate Rdate;
	TZhaoshi *Rzhaoshi;
	int Z_count;
	TMenpai *Rmenpai;
	int MP_count;
	
	bool LoadR(int num);
	bool SaveR(int num);
	bool readData(unsigned char* data, void *& buffer, int offset, int length);
};

